import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'

// 按需导入引入以下包
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// // 或者使用 unplugin-element-plus
// import ElementPlus from 'unplugin-element-plus/vite'


import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    // vueDevTools(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver({ importStyle: 'sass' })]
    })
    // 或者使用 unplugin-element-plus
    // ElementPlus({
    //   useSource: true,
    // }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 使用vite加载scss文件
        additionalData: `@use "@/styles/element/index.scss" as *;`,
        api: 'modern-compiler'
      }
    }
  }
})
